package com.cookie; /**
 * @author wzm
 * @create 2023-03-13 11:23
 */

import com.utils.CookieUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLDecoder;

@WebServlet("/cookie05")
public class CookieServlet05 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Cookie[] cookies = request.getCookies();
        Cookie cookie = CookieUtils.getCookie("username", cookies);
        String value = cookie.getValue();
        System.out.println("value = " + value);
        
        //解码
        String decode = URLDecoder.decode(value, "UTF-8");
        System.out.println("decode = " + decode);


    }
}
